package com.example.controller;

import com.example.designpattern.responsibility_three.IValidatorChain;
import com.example.designpattern.responsibility_two.ParamValidatorChainByDynamic;
import com.example.designpattern.strategy.TestStrategyService;
import com.example.model.GoodsDTO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author long
 * @date 2022/11/30 15:12
 */
@RestController
@RequestMapping("/design")
public class DesignPatternController {

    @Resource
    private IValidatorChain validatorChain;

    @Resource
    private TestStrategyService strategyService;

    //    @Resource
//    private ParamValidatorChain paramValidatorChain;

//    @Resource
//    private ParamValidatorChainByAutowired paramValidatorChainByAutowired;

    @Resource
    private ParamValidatorChainByDynamic paramValidatorChainByDynamic;

    @GetMapping(value= "/testStrategy",produces = "text/plain;charset=UTF-8")
    public String testStrategy(@RequestParam("type") String type) {
        strategyService.handleRequest(type);
        return "处理成功";
    }

    @PostMapping("/testResponsibility_two")
    public String testResponsibilityTwo(@RequestBody GoodsDTO dto) {
//        paramValidatorChain.startParamValidate(dto);
//        paramValidatorChainByAutowired.startParamValidate(dto);
        paramValidatorChainByDynamic.startParamValidate(dto);
        return "success";
    }

    @PostMapping(value = "/testResponsibility_three",produces = "text/plain;charset=UTF-8")
    public String testResponsibilityThree(@RequestBody GoodsDTO dto) {
        validatorChain.validate(dto);
        return "处理成功";
    }


}

